package jmine.tec.sync.dao;

import java.util.List;

import jmine.tec.sync.domain.SynchronizationErrorEntity;
import jmine.tec.sync.domain.enumx.SynchronizationOperationType;

import org.hibernate.Criteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;

import bancosys.tec.persist.dao.BaseDAO;
import bancosys.tec.persist.hibernate.RestrictionsUtils;

/**
 * @author gabriel.silva
 */
public class SynchronizationErrorEntityDAO extends BaseDAO<SynchronizationErrorEntity> {

    /**
     * Procura as entidades por nome, id remoto e origem
     * 
     * @param entityClass {@link String}
     * @param remoteId {@link Long}
     * @param source {@link String}
     * @param type {@link SynchronizationOperationType}
     * @return {@link SynchronizationErrorEntity}
     */
    public List<SynchronizationErrorEntity> findByEntityClassRemoteIdSourceType(String entityClass, Long remoteId, String source,
            SynchronizationOperationType type) {
        Criteria crit = this.createCriteria();
        RestrictionsUtils.addRestrictionLike(crit, "entityClass", entityClass, MatchMode.ANYWHERE);
        RestrictionsUtils.addRestrictionEq(crit, "remoteEntityId", remoteId);
        RestrictionsUtils.addRestrictionEq(crit, "source", source);
        RestrictionsUtils.addRestrictionEq(crit, "operationType", type);
        crit.addOrder(Order.desc("id"));
        return this.executeQuery(crit);
    }

}
